let min = document.querySelectorAll('.min');
let images = document.getElementById('images');
let index = 0;
let time;

function position() {
	images.style.left = (index * -100) + "%";
}

function add() {
	if (index >= min.length - 1) {
		index = 0;
	} else {
		index++;
	}
}

function desc() {
	if (index < 1) {
		index = min.length - 1;
	} else {
		index--;
	}
}

function timer() {
	time = setInterval(() => {
		index++;
		for (let i = 0; i < min.length; i++) {
			if(index == i){
				min[index].style.backgroundColor = "rgb(66,135,255)";
			}else{
				min[i].style.backgroundColor = "rgb(141,149,159)";
			}
			if(index == 4){
				min[0].style.backgroundColor = "rgb(66,135,255)";
			}
		}
		desc();
		add();
		position();
	}, 3000)
}

for (let i = 0; i < min.length; i++) {
	min[i].addEventListener('click', () => {
		index = i;
		for(let j = 0; j<min.length;j++){
			if(j == i){
				min[index].style.backgroundColor = "rgb(66,135,255)";
			}else{
				min[j].style.backgroundColor = "rgb(141,149,159)";
			}
		}
		position();
		clearInterval(time);
		timer();
	})
}

timer();
